<?php
/**
 * Base controller
 *
 * @author Dima
 *
 */

class modules_default_controllers_ControllerBase extends Zend_Controller_Action
{
	/**
	 * Shows if only logged user can access to this controller
	 * @var bool
	 */
	protected $_bForLoggedUsersOnly = true;
	/**
	 * frontpage, doublesided, contentonly
	 * @var string
	 */
	protected $_contentLayout = 'doublesided';
	protected $_role = '';



	public function init()
	{
		$Path 		= 'includes/';
		$Extension  = '.phtml';

		$TopLogoTemplate 	 = $Path . 'toplogo' 	 . $Extension;
		$TopMenuTemplate 	 = $Path . 'topmenu'	 . $Extension;
		$TopFooterTemplate 	 = $Path . 'topfooter'	 . $Extension;
		$UserMenuTemplate 	 = $Path . 'usermenu'	 . $Extension;

		$ContentLayoutTemplate = $Path . 'contentonly_layout'	 . $Extension;

		if (! Lemar_User::isLogged() && $this->_bForLoggedUsersOnly)
		{
			/** If user is not logged in and controller is for logged users only - redirect to start page */

			$oRequest = $this->getRequest();
			$category = $oRequest->getParam('category');
			$oZendSession = Zend_Registry::getInstance()->get('Zend_Session_Namespace');
			$oZendSession->category = $category;

			$this->_redirect('/login/');
		}

		if (Lemar_User::isLogged())
		{
			$UserMenuTemplate 	  = $Path . 'usermenu_logged' . $Extension;
			$this->view->isLogged = 'yes';

			$oZendSession = Zend_Registry::getInstance()->get('Zend_Session_Namespace');

		}
		else
		{

		}

		$oZendSession 			  = Zend_Registry::getInstance()->get('Zend_Session_Namespace');
		$errorMessage 			  = $oZendSession->errorMessage;

		$this->view->ContentLayoutTemplate	= $ContentLayoutTemplate;
		$this->view->TopLogoTemplate 		= $TopLogoTemplate;
		$this->view->TopMenuTemplate 		= $TopMenuTemplate;
		$this->view->TopFooterTemplate 		= $TopFooterTemplate;
		$this->view->UserMenuTemplate 		= $UserMenuTemplate;


		$this->view->headLink()->appendStylesheet('/css/reset.css');
		$this->view->headLink()->appendStylesheet('/css/main.css');
		$this->view->headLink()->appendStylesheet('/css/960.css');
		$this->view->headLink()->appendStylesheet('/css/sexybuttons.css');
		$this->view->headLink()->appendStylesheet('/css/jquery.gritter.css');


		$this->view->headScript()->appendFile('/js/lib/jquery.js');
		$this->view->headScript()->appendFile('/js/lib/jquery.easing.1.3.js');
		$this->view->headScript()->appendFile('/js/lib/jquery.gritter.min.js');
		$this->view->headScript()->appendFile('/js/lib/jquery.validate.js');
		$this->view->headScript()->appendFile('/js/lib/jquery.maskedinput-1.2.2.min.js');

		$this->view->headScript()->appendFile('/js/global.js');
		$this->view->headScript()->appendFile('/js/resources.js');


		$oUser = Lemar_User::getLoggedUser();
		if (isset($oUser->role))
			$this->_role = $oUser->role;
			

		$frontController 			= Zend_Controller_Front::getInstance();

		$this->view->controllerName = $frontController->getRequest()->getControllerName();
		$this->view->actionName 	= $frontController->getRequest()->getActionName();
		$this->view->role 			= $this->_role;
		$this->view->errorMessage 	= $errorMessage;
	}
}
